/**
 * $Id: DatabaseAdditions.m 24 2008-01-09 07:25:37Z robertsaenz $
 */
//
//  DatabaseAdditions.m
//  fmkit
//
//  Created by August Mueller on 10/30/05.
//  Copyright 2005 Flying Meat Inc.. All rights reserved.
//

#import "Database.h"
#import "DatabaseAdditions.h"

@implementation Database (DatabaseAdditions)

- (NSString*) stringForQuery:(NSString*)objs, ...; {

    ResultSet *rs = [self executeQuery:objs];

    if (![rs next]) {
        return nil;
    }

    NSString *ret = [rs stringForColumnIndex:0];

    // clear it out.
    [rs close];

    return ret;
}

- (int) intForQuery:(NSString*)objs, ...; {

    ResultSet *rs = [self executeQuery:objs];

    if (![rs next]) {
        return nil;
    }

    long ret = [rs longForColumnIndex:0];

    // clear it out.
    [rs close];

    return ret;
}

- (long) longForQuery:(NSString*)objs, ...; {

    ResultSet *rs = [self executeQuery:objs];

    if (![rs next]) {
        return nil;
    }

    int ret = [rs intForColumnIndex:0];

    // clear it out.
    [rs close];

    return ret;
}

- (BOOL) boolForQuery:(NSString*)objs, ...; {

    ResultSet *rs = [self executeQuery:objs];

    if (![rs next]) {
        return nil;
    }

    BOOL ret = [rs boolForColumnIndex:0];

    // clear it out.
    [rs close];

    return ret;
}

- (double) doubleForQuery:(NSString*)objs, ...; {

    ResultSet *rs = [self executeQuery:objs];

    if (![rs next]) {
        return nil;
    }

    double ret = [rs doubleForColumnIndex:0];

    // clear it out.
    [rs close];

    return ret;
}

- (NSData*) dataForQuery:(NSString*)objs, ...; {

    ResultSet *rs = [self executeQuery:objs];

    if (![rs next]) {
        return nil;
    }

    NSData *data = [rs dataForColumnIndex:0];

    // clear it out.
    [rs close];

    return data;
}

@end
